<script setup lang="ts">
defineOptions({
  name: "filesInfo"
});

import { ref } from "vue";
import modelBox from "@/views/common/components/modelBox/index.vue";
import FileUpload from "@/components/Upload/FileUpload.vue";
import { queryFileList } from "@/api/modules/fab";

const props = withDefaults(defineProps<{ ids: Array<string> }>(), { ids: () => [] });

const fileList = ref<Array<any>>([]);
const title = ref<string>("关联文档");
const loading = ref<boolean>(false);

const init = async () => {
  loading.value = true;
  fileList.value.splice(0);
  if (!props.ids?.length) {
    loading.value = false;
    return;
  }
  const res = await queryFileList({ ids: props.ids }, () => {
    loading.value = false;
  });
  if (!res?.length) return [];
  fileList.value = res;
  loading.value = false;
};

defineExpose({
  init
});
</script>

<template>
  <modelBox :title="title">
    <div v-loading="loading">
      <FileUpload fileType="view" isPreview :fileList="fileList" />
    </div>
  </modelBox>
</template>
